package com.nmgsr.ptmsapp.adapter;

import android.annotation.SuppressLint;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.nmgsr.beans.responsedao.PtmsToolRes;
import com.nmgsr.ptmsapp.R;
import com.nmgsr.ptmsapp.utils.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class ListPtmsToolAdapter extends BaseQuickAdapter<PtmsToolRes, BaseViewHolder> {
    public ListPtmsToolAdapter() {
        super(R.layout.list_ptms_tool_item);
    }

    @SuppressLint("ResourceAsColor")
    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, PtmsToolRes list) {
        baseViewHolder.setText(R.id.tv_name, list.getToolName());
        baseViewHolder.setText(R.id.tv_epc,"标签:"+ list.getEpc());
        //0在库，1出库，2试验中
        if (list.getToolStatus().equals("0")) {
            baseViewHolder.setText(R.id.tv_toolStatus, "在库");
            baseViewHolder.setTextColor(R.id.tv_toolStatus, 0xFF1296DB);
        } else if (list.getToolStatus().equals("1")) {
            baseViewHolder.setText(R.id.tv_toolStatus, "出库");
            baseViewHolder.setTextColor(R.id.tv_toolStatus,0xFF3cb371);
        } else if (list.getToolStatus().equals("2")) {
            baseViewHolder.setText(R.id.tv_toolStatus, "试验中");
            baseViewHolder.setTextColor(R.id.tv_toolStatus, 0xFFFF0000);
        }
        try {
            String formattedTestDate = DateUtils.formatDate(list.getTestDate(), "yyyy-MM-dd", "yyyy年MM月dd日");
            baseViewHolder.setText(R.id.tv_testDate, "试验日期：" + formattedTestDate);

            String formattedScrapDate = DateUtils.formatDate(list.getScrapDate(), "yyyy-MM-dd", "yyyy年MM月dd日");
            baseViewHolder.setText(R.id.tv_scrapDate, "报废日期：" + formattedScrapDate);

        } catch (Exception e) {
            // 如果你字段可能为空，可以统一处理异常或默认值
            baseViewHolder.setText(R.id.tv_testDate, "日期格式错误");
            baseViewHolder.setText(R.id.tv_scrapDate, "日期格式错误");
        }
    }
}
